<template>
	<view class="menu">
		<search-menu></search-menu>	
		<mall-type-menu @mallShow="mallShow"></mall-type-menu>
		<scroll-view scroll-y="true" class="scroll-Y">
			<mall-list :menuData = "menuData"></mall-list>
		</scroll-view>
	</view>
</template>

<script>
	import searchMenu from "./childMenu/searchMenu.vue"
	import MallTypeMenu from "./childMenu/MallTypeMenu.vue"
	import MallList from "./childMenu/MallList.vue"
	 
	export default {
		data() {
			return {
				mallTypeList:[],
				menuData:[],
			}
		},
		onLoad() {
			uni.request({
				url:"http://www.kangliuyong.com:10002/type",
				data:{
					appkey:"U2FsdGVkX19WSQ59Cg+Fj9jNZPxRC5y0xB1iV06BeNA="
				},
				method:"GET",
				success: (res) => {
					if(res.statusCode == 200){
						this.mallTypeList = res.data.result
					}
				}
			})
			this.hotData()
		},
		components: {
			searchMenu,
			MallTypeMenu,
			MallList
		},
		methods: {
			mallShow(e){
				if(e == "推荐"){
					this.hotData()
				}else {
					for (var i = 0; i < this.mallTypeList.length; i++) {
						if(this.mallTypeList[i].typeDesc == e){
							uni.request({
								url:'http://www.kangliuyong.com:10002/typeProducts',
								data:{
									appkey:"U2FsdGVkX19WSQ59Cg+Fj9jNZPxRC5y0xB1iV06BeNA=",
									key: "type",
									value: this.mallTypeList[i].type
								},
								success:(res)=>{
									if(res.statusCode == 200){
										this.menuData = res.data.result
									}
								}
							})
						}
					}
				}
			},
			hotData(){
				uni.request({
					url:'http://www.kangliuyong.com:10002/typeProducts',
					data:{
						appkey:"U2FsdGVkX19WSQ59Cg+Fj9jNZPxRC5y0xB1iV06BeNA=",
						key: 'isHot',
						value: 1
					},
					success:(res)=>{
						if(res.statusCode == 200){
							this.menuData = res.data.result
						}
					}
				})
			}
		}
	}
</script>

<style scoped>
	.menu{
		position: relative;
		height: 100vh;
	}
	.scroll-Y{
		position: absolute;
		top: 270rpx;
		right: 0rpx;
		left: 0rpx;
		bottom: 0rpx;
	}
</style>
